package luccy.util;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import luccy.exception.IllegalAccessRuntimeException;
import luccy.exception.InvocationTargetRuntimeException;

public abstract class MethodUtil {

	private MethodUtil() {
	}
	
    @SuppressWarnings("unchecked")
	public static <T> T invoke(final Method method, final Object target,
            final Object... args) {
        try {
            return (T) method.invoke(target, args);
        } catch (final IllegalAccessException e) {
            throw new IllegalAccessRuntimeException(method.getDeclaringClass(), e);
        } catch (final InvocationTargetException e) {
            throw new InvocationTargetRuntimeException(method.getDeclaringClass(), e);
        }
    }

}
